/* @(#)GSModifyPasswordConfirmAction.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-3-8     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSOperatorProcessor;
import com.hitrust.gs.form.GSModifyPasswordForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.security.Encryptor;

/**
 * 
 */
public class GSModifyPasswordConfirmAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {
        GSModifyPasswordForm tForm = (GSModifyPasswordForm)aForm;
        try{
            //判断新密码是否为空
            if(tForm.newPwd == null || tForm.newPwd.trim().equals("")
                    || tForm.confirmPwd == null || tForm.confirmPwd.equals("")){
                GSLogWriter.error(this,GSException.E10056_MSG);
                throw new GSException(GSException.E10056,GSException.E10056_MSG);
            }
            //判断新密码和确认新密码是否相等
            if(!tForm.newPwd.equals(tForm.confirmPwd)){
                GSLogWriter.error(this,GSException.E10057_MSG);
                throw new GSException(GSException.E10057,GSException.E10057_MSG);
            }
            //取得当前操作员对象
            GSOperatorBean tOperatorBean = (GSOperatorBean)tForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            if(!Encryptor.encrypt(tForm.oldPwd).equals(tOperatorBean.getGs_oper_pwd())){
                GSLogWriter.debug(this,GSException.E10058_MSG);
                throw new GSException(GSException.E10058,GSException.E10058_MSG);
            }
            //执行修改
            GSOperatorProcessor tOperProc = new GSOperatorProcessor();
            boolean tFlag = tOperProc.modifyPwd(tOperatorBean,Encryptor.encrypt(tForm.newPwd));
            if(!tFlag){
                tForm.getRequest().setAttribute("message","密码修改失败");
            }else{
            	tOperatorBean.setGs_oper_pwd(Encryptor.encrypt(tForm.newPwd));
            	tForm.getSession().setAttribute(GSBaseConstants.LOGIN,tOperatorBean);
                tForm.getRequest().setAttribute("message","密码修改成功");
            }
            tForm.getRequest().setAttribute("action","A600101.do");
        }catch(Exception ge){
            tForm.getRequest().setAttribute("action","A600101.do");
            throw ge;
        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
